load("@py_deps_py310//:requirements.bzl", ci_require = "requirement")
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")

py_library(
    name = "workspace",
    srcs = ["workspace.py"],
    deps = [
        ci_require("pyyaml"),
    ],
)

py_library(
    name = "raydepsets_lib",
    srcs = [
        "cli.py",
    ],
    data = ["//:uv_file"],
    deps = [
        ":workspace",
        ci_require("bazel-runfiles"),
        ci_require("click"),
        ci_require("pyyaml"),
        ci_require("networkx"),
    ],
)

py_binary(
    name = "raydepsets",
    srcs = ["raydepsets.py"],
    exec_compatible_with = ["//bazel:py310"],
    deps = [":raydepsets_lib"],
)

py_test(
    name = "test_cli",
    srcs = ["tests/test_cli.py"],
    data = [
        "tests/test_data/pre-hook-error-test.sh",
        "tests/test_data/pre-hook-test.sh",
        "tests/test_data/requirement_constraints_test.txt",
        "tests/test_data/requirements_compiled_test.txt",
        "tests/test_data/requirements_compiled_test_expand.txt",
        "tests/test_data/requirements_compiled_test_update.txt",
        "tests/test_data/requirements_test.txt",
        "tests/test_data/test.depsets.yaml",
        "tests/test_data/test2.depsets.yaml",
    ],
    exec_compatible_with = ["//bazel:py310"],
    tags = [
        "ci_unit",
        "team:ci",
    ],
    deps = [
        ci_require("pytest"),
        ":raydepsets_lib",
        ":utils",
    ],
)

py_library(
    name = "utils",
    testonly = True,
    srcs = ["tests/utils.py"],
    deps = [
        ci_require("bazel-runfiles"),
    ],
)

py_test(
    name = "test_workspace",
    srcs = ["tests/test_workspace.py"],
    data = [
        "tests/test_data/test.depsets.yaml",
        "tests/test_data/test2.depsets.yaml",
    ],
    tags = [
        "ci_unit",
        "team:ci",
    ],
    deps = [
        ci_require("pytest"),
        ":utils",
        ":workspace",
    ],
)
